package encryptionutil

import (
	"crypto/md5"
	"errors"
	"fmt"
	"strings"
)

// Encryption 加密
func Encryption(src string) (string, error){
	if src == ""{
		return "", errors.New("字符串不能为空")
	}
	data := []byte(src)
	md5data := md5.Sum(data)
	return fmt.Sprintf("%x", md5data), nil
}

// EncryptionCompare 加密对比
func EncryptionCompare(src string, encryptionString string) (bool, error){
	if src == ""{
		return false, errors.New("字符串不能为空")
	}
	md5src, err := Encryption(src)
	if err != nil{
		return false, err
	}
	if strings.EqualFold(md5src, encryptionString){
		return true, nil
	}
	return false, nil
}
